package com.wr.springbootsss.controller;

import com.wr.springbootsss.pojo.Resume;
import com.wr.springbootsss.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 王瑞
 * @description:   首页的cotroller
 * @date 2020/3/11  13:20
 */

@Controller
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/index")
    public String index(Model model){
        List<Resume> resumes = resumeService.selectAll();
        model.addAttribute("resumes",resumes);
        return "index";
    }


    //修改或者新增的handler
    @RequestMapping(value = "/updata",produces = "application/html;charset=UTF-8")
    public String updata(Resume resume){
        Integer id = resume.getId();
        if(id==0){
            resume.setId(null);
        }
        resumeService.sava(resume);
        return "redirect:index";
    }

    //删除的handler
    @RequestMapping("/delData")
    public String delData(Integer id){
        resumeService.deleteById(id);
        return "redirect:index";
    }
}
